package com.tencent.smtt.sdk;

import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import com.sangfor.kevinsawicki.http.HttpRequest;
import com.sangfor.ssl.service.utils.IGeneral;
import com.tencent.smtt.sdk.TbsDownloadConfig;
import com.tencent.smtt.sdk.TbsLogReport;
import com.tencent.smtt.utils.Apn;
import com.tencent.smtt.utils.TbsLog;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.URL;
import java.util.HashSet;
import java.util.Set;
import org.ksoap2.transport.ServiceConnection;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public class ag {
    private static int d = 5;
    private static int e = 1;
    private static final String[] f = {"tbs_downloading_com.tencent.mtt", "tbs_downloading_com.tencent.mm", "tbs_downloading_com.tencent.mobileqq", "tbs_downloading_com.tencent.tbs", "tbs_downloading_com.qzone"};
    private Set<String> A;
    private boolean C;
    String a;
    private Context g;
    private String h;
    private String i;
    private String j;
    private File k;
    private long l;
    private boolean o;
    private int p;
    private int q;
    private boolean r;
    private boolean s;
    private HttpURLConnection t;
    private String u;
    private TbsLogReport.TbsLogInfo v;
    private String w;
    private int x;
    private boolean y;
    private Handler z;
    private int m = IGeneral.TIMEQRY_SLEEP;
    private int n = ServiceConnection.DEFAULT_TIMEOUT;
    private int B = d;
    String[] b = null;
    int c = 0;

    public ag(Context context) {
        Context applicationContext = context.getApplicationContext();
        this.g = applicationContext;
        this.v = TbsLogReport.a(applicationContext).a();
        this.A = new HashSet();
        this.u = "tbs_downloading_" + this.g.getPackageName();
        am.a();
        File t = am.t(this.g);
        this.k = t;
        if (t == null) {
            throw new NullPointerException("TbsCorePrivateDir is null!");
        }
        f();
        this.w = null;
        this.x = -1;
    }

    private long a(long j, long j2) {
        long currentTimeMillis = System.currentTimeMillis();
        this.v.setDownConsumeTime(currentTimeMillis - j);
        this.v.setDownloadSize(j2);
        return currentTimeMillis;
    }

    static File a(Context context) {
        try {
            File file = Build.VERSION.SDK_INT >= 8 ? new File(com.tencent.smtt.utils.j.a(context, 4)) : null;
            if (file != null && !file.exists() && !file.isDirectory()) {
                file.mkdirs();
            }
            return file;
        } catch (Exception e2) {
            e2.printStackTrace();
            TbsLog.e(TbsDownloader.LOGTAG, "[TbsApkDownloader.backupApkPath] Exception is " + e2.getMessage());
            return null;
        }
    }

    private static File a(Context context, int i) {
        File file = new File(com.tencent.smtt.utils.j.a(context, i));
        if (file.exists() && file.isDirectory()) {
            if (new File(file, TbsDownloader.getOverSea(context) ? "x5.oversea.tbs.org" : "x5.tbs.org").exists()) {
                return file;
            }
        }
        return null;
    }

    private String a(Throwable th) {
        String stackTraceString = Log.getStackTraceString(th);
        return stackTraceString.length() > 1024 ? stackTraceString.substring(0, 1024) : stackTraceString;
    }

    private String a(URL url) {
        try {
            return InetAddress.getByName(url.getHost()).getHostAddress();
        } catch (Error e2) {
            e2.printStackTrace();
            return "";
        } catch (Exception e3) {
            e3.printStackTrace();
            return "";
        }
    }

    private void a(int i, String str, boolean z) {
        if (z || this.p > this.B) {
            this.v.setErrorCode(i);
            this.v.setFailDetail(str);
        }
    }

    private void a(long j) {
        this.p++;
        if (j <= 0) {
            try {
                j = m();
            } catch (Exception unused) {
                return;
            }
        }
        Thread.sleep(j);
    }

    private void a(Closeable closeable) {
        if (closeable != null) {
            try {
                closeable.close();
            } catch (IOException unused) {
            }
        }
    }

    public static void a(File file, Context context) {
        File file2;
        if (file != null && file.exists()) {
            try {
                File a = a(context);
                if (a == null) {
                    return;
                }
                if (TbsDownloadConfig.getInstance(context).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_TBS_DOWNLOAD_V_TYPE, 0) == 1) {
                    file2 = new File(a, "x5.tbs.decouple");
                } else {
                    file2 = new File(a, TbsDownloader.getOverSea(context) ? "x5.oversea.tbs.org" : "x5.tbs.org");
                }
                file2.delete();
                com.tencent.smtt.utils.j.b(file, file2);
                if (TbsDownloadConfig.getInstance(context).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_TBS_DOWNLOAD_V_TYPE, 0) == 1 || TbsDownloadConfig.getInstance(context).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_DECOUPLECOREVERSION, 0) != com.tencent.smtt.utils.a.a(context, file)) {
                    return;
                }
                File file3 = new File(a, "x5.tbs.decouple");
                if (com.tencent.smtt.utils.a.a(context, file) == com.tencent.smtt.utils.a.a(context, file3)) {
                    return;
                }
                file3.delete();
                com.tencent.smtt.utils.j.b(file, file3);
            } catch (Exception unused) {
            }
        }
    }

    private void a(String str) {
        URL url = new URL(str);
        HttpURLConnection httpURLConnection = this.t;
        if (httpURLConnection != null) {
            try {
                httpURLConnection.disconnect();
            } catch (Throwable th) {
                TbsLog.e(TbsDownloader.LOGTAG, "[initHttpRequest] mHttpRequest.disconnect() Throwable:" + th.toString());
            }
        }
        HttpURLConnection httpURLConnection2 = (HttpURLConnection) url.openConnection();
        this.t = httpURLConnection2;
        httpURLConnection2.setRequestProperty("User-Agent", TbsDownloader.a(this.g));
        this.t.setRequestProperty(HttpRequest.HEADER_ACCEPT_ENCODING, "identity");
        this.t.setRequestMethod("GET");
        this.t.setInstanceFollowRedirects(false);
        this.t.setConnectTimeout(this.n);
        this.t.setReadTimeout(this.m);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static File b(Context context) {
        try {
            if (Build.VERSION.SDK_INT >= 8) {
                File a = a(context, 4);
                if (a == null) {
                    a = a(context, 3);
                }
                if (a == null) {
                    a = a(context, 2);
                }
                return a == null ? a(context, 1) : a;
            }
            return null;
        } catch (Exception e2) {
            e2.printStackTrace();
            TbsLog.e(TbsDownloader.LOGTAG, "[TbsApkDownloader.backupApkPath] Exception is " + e2.getMessage());
            return null;
        }
    }

    private void b(boolean z) {
        com.tencent.smtt.utils.v.a(this.g);
        TbsDownloadConfig tbsDownloadConfig = TbsDownloadConfig.getInstance(this.g);
        tbsDownloadConfig.a.put(TbsDownloadConfig.TbsConfigKey.KEY_FULL_PACKAGE, false);
        tbsDownloadConfig.a.put(TbsDownloadConfig.TbsConfigKey.KEY_NEEDDOWNLOAD, false);
        tbsDownloadConfig.a.put(TbsDownloadConfig.TbsConfigKey.KEY_DOWNLOAD_INTERRUPT_CODE_REASON, -123);
        tbsDownloadConfig.commit();
        QbSdk.m.onDownloadFinish(z ? 100 : 120);
        int i = tbsDownloadConfig.mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_RESPONSECODE, 0);
        TbsDownloadConfig.getInstance(this.g).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_DOWNLOADDECOUPLECORE, 0);
        if (i != 3 && i <= 10000) {
            am.a().a(this.g, new File(this.k, "x5.tbs").getAbsolutePath(), tbsDownloadConfig.mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_TBS_DOWNLOAD_V, 0));
            a(new File(this.k, "x5.tbs"), this.g);
            return;
        }
        File a = a(this.g);
        if (a == null) {
            d();
            tbsDownloadConfig.a.put(TbsDownloadConfig.TbsConfigKey.KEY_NEEDDOWNLOAD, true);
            tbsDownloadConfig.commit();
            return;
        }
        File file = new File(a, TbsDownloader.getOverSea(this.g) ? "x5.oversea.tbs.org" : "x5.tbs.org");
        int a2 = com.tencent.smtt.utils.a.a(this.g, file);
        File file2 = new File(this.k, "x5.tbs");
        String absolutePath = file2.exists() ? file2.getAbsolutePath() : null;
        int i2 = tbsDownloadConfig.mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_TBS_DOWNLOAD_V, 0);
        Bundle bundle = new Bundle();
        bundle.putInt("operation", i);
        bundle.putInt("old_core_ver", a2);
        bundle.putInt("new_core_ver", i2);
        bundle.putString("old_apk_location", file.getAbsolutePath());
        bundle.putString("new_apk_location", absolutePath);
        bundle.putString("diff_file_location", absolutePath);
        am.a().b(this.g, bundle);
    }

    private boolean b(int i) {
        try {
            File file = new File(this.k, "x5.tbs");
            File a = a(this.g);
            if (a != null) {
                File file2 = new File(a, TbsDownloader.getOverSea(this.g) ? "x5.oversea.tbs.org" : "x5.tbs.org");
                file.delete();
                com.tencent.smtt.utils.j.b(file2, file);
                if (com.tencent.smtt.utils.a.a(this.g, file, 0L, i)) {
                    return true;
                }
                TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.copyTbsApkFromBackupToInstall] verifyTbsApk error!!");
                return false;
            }
            return false;
        } catch (Exception e2) {
            e2.printStackTrace();
            TbsLog.e(TbsDownloader.LOGTAG, "[TbsApkDownloader.copyTbsApkFromBackupToInstall] Exception is " + e2.getMessage());
            return false;
        }
    }

    public static void c(Context context) {
        try {
            am.a();
            File t = am.t(context);
            new File(t, "x5.tbs").delete();
            new File(t, "x5.tbs.temp").delete();
            File a = a(context);
            if (a != null) {
                new File(a, "x5.tbs.org").delete();
                new File(a, "x5.oversea.tbs.org").delete();
            }
        } catch (Exception unused) {
        }
    }

    private boolean c(boolean z) {
        TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.deleteFile] isApk=" + z);
        File file = z ? new File(this.k, "x5.tbs") : new File(this.k, "x5.tbs.temp");
        if (file.exists()) {
            return file.delete();
        }
        return true;
    }

    /* JADX WARN: Code restructure failed: missing block: B:21:0x0085, code lost:
        if (r10 != r8) goto L20;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    private boolean c(boolean r13, boolean r14) {
        /*
            Method dump skipped, instructions count: 490
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: com.tencent.smtt.sdk.ag.c(boolean, boolean):boolean");
    }

    private void f() {
        this.p = 0;
        this.q = 0;
        this.l = -1L;
        this.j = null;
        this.o = false;
        this.r = false;
        this.s = false;
        this.y = false;
    }

    private void g() {
        TbsLogReport a;
        TbsLogReport.EventType eventType;
        TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.closeHttpRequest]");
        HttpURLConnection httpURLConnection = this.t;
        if (httpURLConnection != null) {
            if (!this.r) {
                this.v.setResolveIp(a(httpURLConnection.getURL()));
            }
            try {
                this.t.disconnect();
            } catch (Throwable th) {
                TbsLog.e(TbsDownloader.LOGTAG, "[closeHttpRequest] mHttpRequest.disconnect() Throwable:" + th.toString());
            }
            this.t = null;
        }
        int i = this.v.a;
        if (this.r || !this.y) {
            TbsDownloader.a = false;
            return;
        }
        this.v.setEventTime(System.currentTimeMillis());
        String apnInfo = Apn.getApnInfo(this.g);
        if (apnInfo == null) {
            apnInfo = "";
        }
        int apnType = Apn.getApnType(this.g);
        this.v.setApn(apnInfo);
        this.v.setNetworkType(apnType);
        if (apnType != this.x || !apnInfo.equals(this.w)) {
            this.v.setNetworkChange(0);
        }
        if ((this.v.a == 0 || this.v.a == 107) && this.v.getDownFinalFlag() == 0 && (!Apn.isNetworkAvailable(this.g) || !l())) {
            a(101, null, true);
        }
        if (TbsDownloadConfig.getInstance(this.g).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_DOWNLOADDECOUPLECORE, 0) == 1) {
            a = TbsLogReport.a(this.g);
            eventType = TbsLogReport.EventType.TYPE_DOWNLOAD_DECOUPLE;
        } else {
            a = TbsLogReport.a(this.g);
            eventType = TbsLogReport.EventType.TYPE_DOWNLOAD;
        }
        a.a(eventType, this.v);
        this.v.resetArgs();
        if (i != 100) {
            QbSdk.m.onDownloadFinish(i);
        }
    }

    private boolean h() {
        File file = new File(com.tencent.smtt.utils.j.a(this.g, 4), TbsDownloader.getOverSea(this.g) ? "x5.oversea.tbs.org" : "x5.tbs.org");
        int i = TbsDownloadConfig.getInstance(this.g).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_USE_BACKUP_VERSION, 0);
        if (i == 0) {
            i = TbsDownloadConfig.getInstance(this.g).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_TBS_DOWNLOAD_V, 0);
        }
        return com.tencent.smtt.utils.a.a(this.g, file, 0L, i);
    }

    private void i() {
        try {
            if (TbsDownloadConfig.getInstance(this.g).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_DOWNLOADDECOUPLECORE, 0) == 1) {
                return;
            }
            File file = new File(com.tencent.smtt.utils.j.a(this.g, 4), TbsDownloader.getOverSea(this.g) ? "x5.oversea.tbs.org" : "x5.tbs.org");
            if (file.exists()) {
                file.delete();
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }

    private boolean j() {
        return new File(this.k, "x5.tbs.temp").exists();
    }

    private long k() {
        File file = new File(this.k, "x5.tbs.temp");
        if (file.exists()) {
            return file.length();
        }
        return 0L;
    }

    private boolean l() {
        InputStreamReader inputStreamReader;
        BufferedReader bufferedReader;
        Throwable th;
        InputStream inputStream;
        boolean z = false;
        try {
            inputStream = Runtime.getRuntime().exec("ping www.qq.com").getInputStream();
            try {
                inputStreamReader = new InputStreamReader(inputStream);
                try {
                    bufferedReader = new BufferedReader(inputStreamReader);
                    int i = 0;
                    do {
                        try {
                            String readLine = bufferedReader.readLine();
                            if (readLine == null) {
                                break;
                            } else if (readLine.contains("TTL") || readLine.contains("ttl")) {
                                z = true;
                                break;
                            } else {
                                i++;
                            }
                        } catch (Throwable th2) {
                            th = th2;
                            try {
                                th.printStackTrace();
                                return z;
                            } finally {
                                a(inputStream);
                                a(inputStreamReader);
                                a(bufferedReader);
                            }
                        }
                    } while (i < 5);
                } catch (Throwable th3) {
                    bufferedReader = null;
                    th = th3;
                }
            } catch (Throwable th4) {
                bufferedReader = null;
                th = th4;
                inputStreamReader = null;
            }
        } catch (Throwable th5) {
            inputStreamReader = null;
            bufferedReader = null;
            th = th5;
            inputStream = null;
        }
        return z;
    }

    private long m() {
        int i = this.p;
        return (i == 1 || i == 2) ? i * 20000 : (i == 3 || i == 4) ? 100000L : 200000L;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public boolean n() {
        HttpURLConnection httpURLConnection;
        boolean z = false;
        boolean z2 = Apn.getApnType(this.g) == 3;
        TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDwonloader.detectWifiNetworkAvailable] isWifi=" + z2);
        String str = null;
        HttpURLConnection httpURLConnection2 = null;
        if (z2) {
            String wifiSSID = Apn.getWifiSSID(this.g);
            TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDwonloader.detectWifiNetworkAvailable] localBSSID=" + wifiSSID);
            try {
                httpURLConnection = (HttpURLConnection) new URL("http://pms.mb.qq.com/rsp204").openConnection();
            } catch (Throwable th) {
                th = th;
            }
            try {
                httpURLConnection.setInstanceFollowRedirects(false);
                httpURLConnection.setConnectTimeout(IGeneral.LINE_CONN_SERVICE_TIMEOUT);
                httpURLConnection.setReadTimeout(IGeneral.LINE_CONN_SERVICE_TIMEOUT);
                httpURLConnection.setUseCaches(false);
                httpURLConnection.getInputStream();
                int responseCode = httpURLConnection.getResponseCode();
                TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDwonloader.detectWifiNetworkAvailable] responseCode=" + responseCode);
                boolean z3 = responseCode == 204;
                if (httpURLConnection != null) {
                    try {
                        httpURLConnection.disconnect();
                    } catch (Exception unused) {
                    }
                }
                str = wifiSSID;
                z = z3;
            } catch (Throwable th2) {
                th = th2;
                httpURLConnection2 = httpURLConnection;
                try {
                    th.printStackTrace();
                    if (httpURLConnection2 != null) {
                        try {
                            httpURLConnection2.disconnect();
                        } catch (Exception unused2) {
                        }
                    }
                    str = wifiSSID;
                    if (!z) {
                        this.A.add(str);
                        o();
                        this.z.sendMessageDelayed(this.z.obtainMessage(150, str), 120000L);
                    }
                    if (z) {
                        this.A.remove(str);
                    }
                    return z;
                } catch (Throwable th3) {
                    if (httpURLConnection2 != null) {
                        try {
                            httpURLConnection2.disconnect();
                        } catch (Exception unused3) {
                        }
                    }
                    throw th3;
                }
            }
        }
        if (!z && !TextUtils.isEmpty(str) && !this.A.contains(str)) {
            this.A.add(str);
            o();
            this.z.sendMessageDelayed(this.z.obtainMessage(150, str), 120000L);
        }
        if (z && this.A.contains(str)) {
            this.A.remove(str);
        }
        return z;
    }

    private void o() {
        if (this.z == null) {
            this.z = new ah(this, al.a().getLooper());
        }
    }

    public void a(int i) {
        try {
            File file = new File(this.k, "x5.tbs");
            int a = com.tencent.smtt.utils.a.a(this.g, file);
            if (-1 == a || (i > 0 && i == a)) {
                file.delete();
            }
        } catch (Exception unused) {
        }
    }

    public boolean a() {
        TbsLog.i("TbsApkDownloader", "verifyAndInstallDecoupleCoreFromBackup #1");
        try {
            File file = new File(com.tencent.smtt.utils.j.a(this.g, 4), "x5.tbs.decouple");
            if (file.exists()) {
                TbsLog.i("TbsApkDownloader", "verifyAndInstallDecoupleCoreFromBackup #2");
            } else {
                File b = TbsDownloader.b(TbsDownloadConfig.getInstance(this.g).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_DECOUPLECOREVERSION, -1));
                if (b != null && b.exists()) {
                    com.tencent.smtt.utils.j.b(b, file);
                }
            }
            Context context = this.g;
            if (com.tencent.smtt.utils.a.a(context, file, 0L, TbsDownloadConfig.getInstance(context).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_DECOUPLECOREVERSION, -1))) {
                TbsLog.i("TbsApkDownloader", "verifyAndInstallDecoupleCoreFromBackup #3");
                return am.a().e(this.g);
            }
            TbsLog.i("TbsApkDownloader", "verifyAndInstallDecoupleCoreFromBackup no backup file !!!");
            File file2 = new File(com.tencent.smtt.utils.j.a(this.g, 4), "x5.tbs.decouple");
            if (file2.exists()) {
                file2.delete();
                return false;
            }
            return false;
        } catch (Exception unused) {
            return false;
        }
    }

    public boolean a(boolean z) {
        String[] strArr;
        int i;
        if ((!z || n() || (QbSdk.getDownloadWithoutWifi() && Apn.isNetworkAvailable(this.g))) && (strArr = this.b) != null && (i = this.c) >= 0 && i < strArr.length) {
            this.c = i + 1;
            this.j = strArr[i];
            this.p = 0;
            this.q = 0;
            this.l = -1L;
            this.o = false;
            this.r = false;
            this.s = false;
            this.y = false;
            return true;
        }
        return false;
    }

    /* JADX WARN: Removed duplicated region for block: B:30:0x0082  */
    /* JADX WARN: Removed duplicated region for block: B:40:0x00e9  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public boolean a(boolean r9, boolean r10) {
        /*
            Method dump skipped, instructions count: 314
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: com.tencent.smtt.sdk.ag.a(boolean, boolean):boolean");
    }

    public int b() {
        File a = a(this.g);
        if (a == null) {
            return 0;
        }
        return com.tencent.smtt.utils.a.a(this.g, new File(a, TbsDownloader.getOverSea(this.g) ? "x5.oversea.tbs.org" : "x5.tbs.org"));
    }

    /* JADX WARN: Can't wrap try/catch for region: R(12:(2:323|324)|(3:562|563|(10:565|330|331|332|334|335|336|(3:337|338|(1:536)(4:340|341|342|(1:509)(7:344|(2:346|(1:489)(4:348|349|350|(2:481|482)))(1:508)|352|353|354|(5:356|(3:358|359|360)(1:404)|(1:403)(2:364|(1:399))|400|401)(2:405|406)|402)))|483|(9:377|378|380|(1:382)(1:385)|383|384|123|124|125)(2:388|389)))|(1:561)(1:329)|330|331|332|334|335|336|(4:337|338|(0)(0)|402)|483|(0)(0)) */
    /* JADX WARN: Can't wrap try/catch for region: R(13:323|324|(3:562|563|(10:565|330|331|332|334|335|336|(3:337|338|(1:536)(4:340|341|342|(1:509)(7:344|(2:346|(1:489)(4:348|349|350|(2:481|482)))(1:508)|352|353|354|(5:356|(3:358|359|360)(1:404)|(1:403)(2:364|(1:399))|400|401)(2:405|406)|402)))|483|(9:377|378|380|(1:382)(1:385)|383|384|123|124|125)(2:388|389)))|(1:561)(1:329)|330|331|332|334|335|336|(4:337|338|(0)(0)|402)|483|(0)(0)) */
    /* JADX WARN: Can't wrap try/catch for region: R(14:105|(2:107|(2:109|(2:201|(3:262|263|(5:269|270|272|(1:274)|275)(4:265|266|(4:268|130|131|132)|133))(8:203|(2:257|(2:259|260))|207|(1:255)(2:209|(1:(2:240|(1:251)(4:246|247|(2:249|120)|121))(2:231|(4:236|237|(4:239|130|131|132)|133)(3:233|(2:235|120)|121)))(2:213|(4:218|219|(4:221|130|131|132)|133)(3:215|(2:217|120)|121)))|122|123|124|125))(3:113|114|(8:116|117|(2:119|120)|121|122|123|124|125)(4:126|127|(4:129|130|131|132)|133))))|278|279|280|281|282|(2:284|(4:286|(1:295)(5:299|(2:301|(6:303|(1:305)(1:306)|122|123|124|125)(1:307))(1:314)|308|309|310)|(2:297|132)|133))|316|317|318|320|321|(13:323|324|(3:562|563|(10:565|330|331|332|334|335|336|(3:337|338|(1:536)(4:340|341|342|(1:509)(7:344|(2:346|(1:489)(4:348|349|350|(2:481|482)))(1:508)|352|353|354|(5:356|(3:358|359|360)(1:404)|(1:403)(2:364|(1:399))|400|401)(2:405|406)|402)))|483|(9:377|378|380|(1:382)(1:385)|383|384|123|124|125)(2:388|389)))|(1:561)(1:329)|330|331|332|334|335|336|(4:337|338|(0)(0)|402)|483|(0)(0))(2:578|579)) */
    /* JADX WARN: Code restructure failed: missing block: B:198:0x04d7, code lost:
        if (r2 == 0) goto L130;
     */
    /* JADX WARN: Code restructure failed: missing block: B:202:0x04eb, code lost:
        if (r2 == 0) goto L120;
     */
    /* JADX WARN: Code restructure failed: missing block: B:242:0x0587, code lost:
        if (r2 == 0) goto L130;
     */
    /* JADX WARN: Code restructure failed: missing block: B:276:0x0696, code lost:
        r11 = r4;
     */
    /* JADX WARN: Code restructure failed: missing block: B:307:0x071e, code lost:
        com.tencent.smtt.utils.TbsLog.i(r11, "STEP 1/2 begin downloading...Canceled!", true);
        com.tencent.smtt.sdk.TbsDownloadConfig.getInstance(r39.g).setDownloadInterruptCode(-309);
     */
    /* JADX WARN: Code restructure failed: missing block: B:308:0x072f, code lost:
        r33 = r10;
     */
    /* JADX WARN: Code restructure failed: missing block: B:309:0x0731, code lost:
        r10 = r11;
        r5 = false;
     */
    /* JADX WARN: Code restructure failed: missing block: B:311:0x0735, code lost:
        r11 = r4;
     */
    /* JADX WARN: Code restructure failed: missing block: B:320:0x0752, code lost:
        if (r39.b == null) goto L521;
     */
    /* JADX WARN: Code restructure failed: missing block: B:322:0x0759, code lost:
        if (c(true, r4) != false) goto L521;
     */
    /* JADX WARN: Code restructure failed: missing block: B:323:0x075b, code lost:
        if (r2 != 0) goto L520;
     */
    /* JADX WARN: Code restructure failed: missing block: B:325:0x0761, code lost:
        if (a(false) == false) goto L520;
     */
    /* JADX WARN: Code restructure failed: missing block: B:326:0x0763, code lost:
        r10 = r11;
        r5 = true;
     */
    /* JADX WARN: Code restructure failed: missing block: B:327:0x0766, code lost:
        r39.s = true;
        r10 = r11;
        r5 = false;
        r16 = false;
     */
    /* JADX WARN: Code restructure failed: missing block: B:328:0x0770, code lost:
        r39.s = true;
     */
    /* JADX WARN: Code restructure failed: missing block: B:329:0x0775, code lost:
        if (r39.b == null) goto L524;
     */
    /* JADX WARN: Code restructure failed: missing block: B:330:0x0777, code lost:
        r16 = true;
     */
    /* JADX WARN: Code restructure failed: missing block: B:331:0x0779, code lost:
        com.tencent.smtt.sdk.TbsDownloadConfig.getInstance(r39.g).setDownloadInterruptCode(-311);
     */
    /* JADX WARN: Code restructure failed: missing block: B:342:0x07b0, code lost:
        com.tencent.smtt.utils.TbsLog.i(r17, r28, true);
        r3 = new java.lang.StringBuilder();
        r3.append("downloadFlow=");
        r3.append(r10);
        r3.append(" downloadMaxflow=");
     */
    /* JADX WARN: Code restructure failed: missing block: B:343:0x07c5, code lost:
        r6 = r26;
     */
    /* JADX WARN: Code restructure failed: missing block: B:344:0x07c7, code lost:
        r3.append(r6);
        a(112, r3.toString(), true);
        com.tencent.smtt.sdk.TbsDownloadConfig.getInstance(r39.g).setDownloadInterruptCode(-307);
     */
    /* JADX WARN: Code restructure failed: missing block: B:345:0x07df, code lost:
        r26 = r6;
        r31 = r10;
        r10 = r17;
     */
    /* JADX WARN: Code restructure failed: missing block: B:346:0x07e6, code lost:
        r0 = th;
     */
    /* JADX WARN: Code restructure failed: missing block: B:348:0x07ea, code lost:
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:349:0x07eb, code lost:
        r26 = r6;
     */
    /* JADX WARN: Code restructure failed: missing block: B:350:0x07ee, code lost:
        r0 = th;
     */
    /* JADX WARN: Code restructure failed: missing block: B:351:0x07ef, code lost:
        r7 = r15;
        r5 = r0;
     */
    /* JADX WARN: Code restructure failed: missing block: B:352:0x07f8, code lost:
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:353:0x07f9, code lost:
        r8 = r10;
        r11 = r4;
        r10 = r17;
        r4 = r33;
     */
    /* JADX WARN: Code restructure failed: missing block: B:384:0x08e4, code lost:
        c();
     */
    /* JADX WARN: Code restructure failed: missing block: B:385:0x08e9, code lost:
        if (com.tencent.smtt.sdk.QbSdk.m == null) goto L374;
     */
    /* JADX WARN: Code restructure failed: missing block: B:386:0x08eb, code lost:
        com.tencent.smtt.sdk.QbSdk.m.onDownloadFinish(111);
     */
    /* JADX WARN: Code restructure failed: missing block: B:387:0x08f2, code lost:
        com.tencent.smtt.utils.TbsLog.i(r10, "Download is paused due to NOT_WIFI error!", false);
        com.tencent.smtt.sdk.TbsDownloadConfig.getInstance(r39.g).setDownloadInterruptCode(-304);
     */
    /* JADX WARN: Code restructure failed: missing block: B:388:0x0903, code lost:
        r5 = false;
        r11 = r11;
     */
    /* JADX WARN: Code restructure failed: missing block: B:421:0x099d, code lost:
        r0 = th;
     */
    /* JADX WARN: Code restructure failed: missing block: B:423:0x09a6, code lost:
        r0 = e;
     */
    /* JADX WARN: Code restructure failed: missing block: B:424:0x09a7, code lost:
        r38 = r11;
        r11 = r4;
        r4 = r10;
        r10 = r38;
     */
    /* JADX WARN: Code restructure failed: missing block: B:425:0x09af, code lost:
        r5 = r0;
        r11 = r11;
     */
    /* JADX WARN: Code restructure failed: missing block: B:426:0x09b2, code lost:
        r0 = move-exception;
     */
    /* JADX WARN: Code restructure failed: missing block: B:427:0x09b3, code lost:
        r5 = r0;
        r7 = null;
     */
    /* JADX WARN: Code restructure failed: missing block: B:428:0x09bd, code lost:
        r0 = move-exception;
     */
    /* JADX WARN: Code restructure failed: missing block: B:429:0x09be, code lost:
        r38 = r11;
        r11 = r4;
        r4 = r10;
        r10 = r38;
        r5 = r0;
     */
    /* JADX WARN: Code restructure failed: missing block: B:435:0x09e8, code lost:
        a(r15);
        a(r13);
        a(r12);
     */
    /* JADX WARN: Code restructure failed: missing block: B:436:0x09f3, code lost:
        if (r39.s != false) goto L393;
     */
    /* JADX WARN: Code restructure failed: missing block: B:437:0x09f5, code lost:
        com.tencent.smtt.sdk.TbsDownloadConfig.getInstance(r39.g).setDownloadInterruptCode(-319);
     */
    /* JADX WARN: Code restructure failed: missing block: B:438:0x0a00, code lost:
        if (r2 != 0) goto L135;
     */
    /* JADX WARN: Code restructure failed: missing block: B:439:0x0a02, code lost:
        r2 = com.tencent.smtt.sdk.TbsDownloadConfig.getInstance(r39.g).a;
        r3 = java.lang.Long.valueOf(r8);
        r11 = r11;
     */
    /* JADX WARN: Code restructure failed: missing block: B:442:0x0a1c, code lost:
        r0 = move-exception;
     */
    /* JADX WARN: Code restructure failed: missing block: B:443:0x0a1d, code lost:
        r5 = r0;
        r7 = null;
        r12 = null;
     */
    /* JADX WARN: Code restructure failed: missing block: B:445:0x0a29, code lost:
        r0 = move-exception;
     */
    /* JADX WARN: Code restructure failed: missing block: B:446:0x0a2a, code lost:
        r38 = r11;
        r11 = r4;
        r4 = r10;
        r10 = r38;
        r5 = r0;
        r12 = null;
     */
    /* JADX WARN: Code restructure failed: missing block: B:481:0x0ad9, code lost:
        if (r2 == 0) goto L433;
     */
    /* JADX WARN: Code restructure failed: missing block: B:486:0x0afb, code lost:
        if (r2 == 0) goto L433;
     */
    /* JADX WARN: Code restructure failed: missing block: B:487:0x0afd, code lost:
        com.tencent.smtt.sdk.TbsDownloadConfig.getInstance(r39.g).a.put(r4, java.lang.Long.valueOf(r21));
        com.tencent.smtt.sdk.TbsDownloadConfig.getInstance(r39.g).commit();
     */
    /* JADX WARN: Code restructure failed: missing block: B:488:0x0b15, code lost:
        r14 = r4;
        r4 = r11;
        r8 = r21;
        r3 = r23;
        r12 = r26;
     */
    /* JADX WARN: Code restructure failed: missing block: B:499:0x0b3d, code lost:
        r0 = th;
     */
    /* JADX WARN: Code restructure failed: missing block: B:501:0x0b3f, code lost:
        r0 = th;
     */
    /* JADX WARN: Code restructure failed: missing block: B:502:0x0b40, code lost:
        r38 = r11;
        r11 = r4;
        r4 = r10;
        r10 = r38;
     */
    /* JADX WARN: Code restructure failed: missing block: B:503:0x0b47, code lost:
        r0 = th;
     */
    /* JADX WARN: Code restructure failed: missing block: B:504:0x0b48, code lost:
        r10 = r11;
        r11 = r4;
        r4 = r13;
     */
    /* JADX WARN: Code restructure failed: missing block: B:71:0x0213, code lost:
        if (r2 == 0) goto L643;
     */
    /* JADX WARN: Code restructure failed: missing block: B:72:0x0215, code lost:
        r2 = com.tencent.smtt.sdk.TbsDownloadConfig.getInstance(r39.g).a;
        r3 = java.lang.Long.valueOf(r8);
        r2.put(r14, r3);
        r3 = r3;
        r12 = r12;
        r14 = r14;
     */
    /* JADX WARN: Code restructure failed: missing block: B:78:0x0250, code lost:
        if (r2 == 0) goto L643;
     */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:139:0x03a0 A[Catch: all -> 0x0379, TRY_ENTER, TRY_LEAVE, TryCatch #36 {all -> 0x0379, blocks: (B:123:0x036f, B:125:0x0374, B:139:0x03a0, B:142:0x03ca, B:144:0x03d2, B:146:0x03db, B:150:0x03e9, B:152:0x03f0, B:153:0x03f7, B:148:0x03e1, B:156:0x0401, B:252:0x05cf, B:254:0x05d5, B:256:0x05f6, B:258:0x05fc, B:260:0x0602, B:262:0x060a, B:264:0x060e, B:131:0x0385, B:112:0x0318), top: B:606:0x036f }] */
    /* JADX WARN: Removed duplicated region for block: B:142:0x03ca A[Catch: all -> 0x0379, TRY_ENTER, TryCatch #36 {all -> 0x0379, blocks: (B:123:0x036f, B:125:0x0374, B:139:0x03a0, B:142:0x03ca, B:144:0x03d2, B:146:0x03db, B:150:0x03e9, B:152:0x03f0, B:153:0x03f7, B:148:0x03e1, B:156:0x0401, B:252:0x05cf, B:254:0x05d5, B:256:0x05f6, B:258:0x05fc, B:260:0x0602, B:262:0x060a, B:264:0x060e, B:131:0x0385, B:112:0x0318), top: B:606:0x036f }] */
    /* JADX WARN: Removed duplicated region for block: B:160:0x0421  */
    /* JADX WARN: Removed duplicated region for block: B:316:0x0745  */
    /* JADX WARN: Removed duplicated region for block: B:451:0x0a3d A[Catch: all -> 0x0b2e, TRY_LEAVE, TryCatch #9 {all -> 0x0b2e, blocks: (B:449:0x0a36, B:451:0x0a3d), top: B:581:0x0a36 }] */
    /* JADX WARN: Removed duplicated region for block: B:516:0x0b61 A[ADDED_TO_REGION] */
    /* JADX WARN: Removed duplicated region for block: B:529:0x0bd7  */
    /* JADX WARN: Removed duplicated region for block: B:548:0x0c2e  */
    /* JADX WARN: Removed duplicated region for block: B:549:0x0c42  */
    /* JADX WARN: Removed duplicated region for block: B:555:0x0c6d  */
    /* JADX WARN: Removed duplicated region for block: B:583:0x0906 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:620:0x071e A[EDGE_INSN: B:620:0x071e->B:307:0x071e ?: BREAK  , EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:643:0x0940 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:651:0x0adc A[ADDED_TO_REGION, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:656:0x0bb5 A[EDGE_INSN: B:656:0x0bb5->B:524:0x0bb5 ?: BREAK  , SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:673:0x0401 A[SYNTHETIC] */
    /* JADX WARN: Type inference failed for: r11v3, types: [boolean] */
    /* JADX WARN: Type inference failed for: r11v61 */
    /* JADX WARN: Type inference failed for: r11v64 */
    /* JADX WARN: Type inference failed for: r12v17 */
    /* JADX WARN: Type inference failed for: r12v38 */
    /* JADX WARN: Type inference failed for: r12v40 */
    /* JADX WARN: Type inference failed for: r14v0, types: [java.lang.String] */
    /* JADX WARN: Type inference failed for: r14v1, types: [java.lang.Object] */
    /* JADX WARN: Type inference failed for: r14v12 */
    /* JADX WARN: Type inference failed for: r14v13 */
    /* JADX WARN: Type inference failed for: r14v14 */
    /* JADX WARN: Type inference failed for: r14v15 */
    /* JADX WARN: Type inference failed for: r14v16 */
    /* JADX WARN: Type inference failed for: r14v19 */
    /* JADX WARN: Type inference failed for: r14v28, types: [long] */
    /* JADX WARN: Type inference failed for: r14v38 */
    /* JADX WARN: Type inference failed for: r14v39 */
    /* JADX WARN: Type inference failed for: r14v40 */
    /* JADX WARN: Type inference failed for: r14v41 */
    /* JADX WARN: Type inference failed for: r14v42 */
    /* JADX WARN: Type inference failed for: r14v43 */
    /* JADX WARN: Type inference failed for: r14v44 */
    /* JADX WARN: Type inference failed for: r14v45 */
    /* JADX WARN: Type inference failed for: r14v50 */
    /* JADX WARN: Type inference failed for: r14v51 */
    /* JADX WARN: Type inference failed for: r14v52 */
    /* JADX WARN: Type inference failed for: r14v53 */
    /* JADX WARN: Type inference failed for: r14v54 */
    /* JADX WARN: Type inference failed for: r14v55 */
    /* JADX WARN: Type inference failed for: r14v56 */
    /* JADX WARN: Type inference failed for: r14v58 */
    /* JADX WARN: Type inference failed for: r14v59 */
    /* JADX WARN: Type inference failed for: r14v60 */
    /* JADX WARN: Type inference failed for: r14v61 */
    /* JADX WARN: Type inference failed for: r14v62 */
    /* JADX WARN: Type inference failed for: r14v63 */
    /* JADX WARN: Type inference failed for: r14v66 */
    /* JADX WARN: Type inference failed for: r14v67 */
    /* JADX WARN: Type inference failed for: r14v68 */
    /* JADX WARN: Type inference failed for: r15v3, types: [android.content.SharedPreferences] */
    /* JADX WARN: Type inference failed for: r2v1 */
    /* JADX WARN: Type inference failed for: r2v22 */
    /* JADX WARN: Type inference failed for: r2v33 */
    /* JADX WARN: Type inference failed for: r2v34 */
    /* JADX WARN: Type inference failed for: r2v35 */
    /* JADX WARN: Type inference failed for: r2v37, types: [com.tencent.smtt.sdk.TbsDownloadConfig] */
    /* JADX WARN: Type inference failed for: r2v38 */
    /* JADX WARN: Type inference failed for: r2v6, types: [com.tencent.smtt.sdk.TbsLogReport$TbsLogInfo] */
    /* JADX WARN: Type inference failed for: r2v78 */
    /* JADX WARN: Type inference failed for: r2v79 */
    /* JADX WARN: Type inference failed for: r2v80 */
    /* JADX WARN: Type inference failed for: r2v81 */
    /* JADX WARN: Type inference failed for: r2v82 */
    /* JADX WARN: Type inference failed for: r2v83 */
    /* JADX WARN: Type inference failed for: r2v84 */
    /* JADX WARN: Type inference failed for: r39v0, types: [com.tencent.smtt.sdk.ag] */
    /* JADX WARN: Type inference failed for: r3v0, types: [java.lang.String] */
    /* JADX WARN: Type inference failed for: r3v1, types: [java.lang.Object, java.lang.String] */
    /* JADX WARN: Type inference failed for: r3v124, types: [java.lang.StringBuilder] */
    /* JADX WARN: Type inference failed for: r3v125, types: [java.lang.String] */
    /* JADX WARN: Type inference failed for: r3v126 */
    /* JADX WARN: Type inference failed for: r3v127 */
    /* JADX WARN: Type inference failed for: r3v132, types: [boolean] */
    /* JADX WARN: Type inference failed for: r3v134, types: [boolean] */
    /* JADX WARN: Type inference failed for: r3v135 */
    /* JADX WARN: Type inference failed for: r3v136 */
    /* JADX WARN: Type inference failed for: r3v143, types: [com.tencent.smtt.sdk.TbsDownloadConfig] */
    /* JADX WARN: Type inference failed for: r3v145, types: [com.tencent.smtt.sdk.TbsDownloadConfig] */
    /* JADX WARN: Type inference failed for: r3v147, types: [com.tencent.smtt.sdk.TbsDownloadConfig] */
    /* JADX WARN: Type inference failed for: r3v151, types: [com.tencent.smtt.sdk.TbsDownloadConfig] */
    /* JADX WARN: Type inference failed for: r3v156, types: [com.tencent.smtt.sdk.TbsDownloadConfig] */
    /* JADX WARN: Type inference failed for: r3v167, types: [com.tencent.smtt.sdk.TbsDownloadConfig] */
    /* JADX WARN: Type inference failed for: r3v176 */
    /* JADX WARN: Type inference failed for: r3v179 */
    /* JADX WARN: Type inference failed for: r3v180 */
    /* JADX WARN: Type inference failed for: r3v181 */
    /* JADX WARN: Type inference failed for: r3v182 */
    /* JADX WARN: Type inference failed for: r3v183 */
    /* JADX WARN: Type inference failed for: r3v24 */
    /* JADX WARN: Type inference failed for: r3v25 */
    /* JADX WARN: Type inference failed for: r3v26 */
    /* JADX WARN: Type inference failed for: r3v27 */
    /* JADX WARN: Type inference failed for: r3v28 */
    /* JADX WARN: Type inference failed for: r3v44, types: [com.tencent.smtt.sdk.TbsDownloadConfig] */
    /* JADX WARN: Type inference failed for: r4v22 */
    /* JADX WARN: Type inference failed for: r4v23 */
    /* JADX WARN: Type inference failed for: r4v24 */
    /* JADX WARN: Type inference failed for: r4v25 */
    /* JADX WARN: Type inference failed for: r4v27 */
    /* JADX WARN: Type inference failed for: r4v28 */
    /* JADX WARN: Type inference failed for: r4v6 */
    /* JADX WARN: Type inference failed for: r4v7, types: [boolean] */
    /* JADX WARN: Type inference failed for: r4v71 */
    /* JADX WARN: Type inference failed for: r4v73 */
    /* JADX WARN: Type inference failed for: r4v74 */
    /* JADX WARN: Type inference failed for: r4v75 */
    /* JADX WARN: Type inference failed for: r4v8, types: [boolean] */
    /* JADX WARN: Type inference failed for: r6v43, types: [java.lang.StringBuilder] */
    /* JADX WARN: Type inference failed for: r9v16, types: [int] */
    /* JADX WARN: Type inference failed for: r9v43 */
    /* JADX WARN: Type inference failed for: r9v44 */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public void b(boolean r40, boolean r41) {
        /*
            Method dump skipped, instructions count: 3263
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: com.tencent.smtt.sdk.ag.b(boolean, boolean):void");
    }

    public void c() {
        TbsLogReport a;
        TbsLogReport.EventType eventType;
        this.r = true;
        if (TbsShareManager.isThirdPartyApp(this.g)) {
            TbsLogReport.TbsLogInfo a2 = TbsLogReport.a(this.g).a();
            a2.setErrorCode(-309);
            a2.setFailDetail(new Exception());
            if (TbsDownloadConfig.getInstance(this.g).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_DOWNLOADDECOUPLECORE, 0) == 1) {
                a = TbsLogReport.a(this.g);
                eventType = TbsLogReport.EventType.TYPE_DOWNLOAD_DECOUPLE;
            } else {
                a = TbsLogReport.a(this.g);
                eventType = TbsLogReport.EventType.TYPE_DOWNLOAD;
            }
            a.a(eventType, a2);
        }
    }

    public void d() {
        c();
        c(false);
        c(true);
    }

    public boolean e() {
        TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.isDownloadForeground] mIsDownloadForeground=" + this.C);
        return this.C;
    }
}
